<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${ctx}/res/css/default.css">
<link rel="stylesheet" type="text/css" href="${ctx}/res/css/easyui.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/res/css/icon.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/res/css/style.css">
<link rel="stylesheet" type="text/css"
	href="${ctx}/res/css/lq.fieldset.css">
<script type="text/javascript" src="${ctx}/res/js/jquery.min.js"></script>
<script type="text/javascript" src="${ctx}/res/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/res/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/res/js/lq.fieldset.js"></script>
<script type="text/javascript" src="${ctx}/res/js/base.js"></script>
<script type="text/javascript" src="${ctx}/res/js/pager.js"></script>
<script type="text/javascript">
	$(function() {
		doSearch();
	})
	//查询数据
	function paramData() {
		var param = {}
		return param;
	}
	//查询
	function doSearch() {
		var param = paramData();
		$("#list").datagrid({
			url : "${ctx}/order/search",
			queryParams : param,
			loadFilter : pagerFilter
		});
	}
	//去添加
	function toAdd(appen) {
		$("#fs").form("clear");
		$("#adminMethod").val(appen);
		if (appen == 2) {
			toUpdateUnit();
		}
		$('#AdminAdd').window('open');
	}
	//修改
	function toUpdateUnit() {
		var row = $("#list").datagrid("getSelected");
		$('#orderId').val(row.orderId);
		$("#orderPayment").textbox("setValue", row.orderPayment);
		$("#orderAddress").textbox("setValue", row.orderAddress);

		$("#orderEmail").textbox("setValue", row.orderEmail);
		$("#orderUser").textbox("setValue", row.orderUser);
		$("#orderSum").textbox("setValue", row.orderSum);
	}

	//保存
	function save() {

		var adminMethod = $("#adminMethod").val();
		if (adminMethod == 1) {
			var url = "${ctx}/order/add";
		}
		if (adminMethod == 2) {
			var url = "${ctx}/order/update";
		}
		var orderId = $("#orderId").val();
		var orderPayment = $("#orderPayment").textbox("getValue");
		var orderAddress = $("#orderAddress").textbox("getValue");
		var orderEmail = $("#orderEmail").textbox("getValue");
		var orderUser = $("#orderUser").textbox("getValue");
		var orderSum = $("#orderSum").textbox("getValue");

		var postData = {
			'orderId' : orderId,
			'orderPayment' : orderPayment,
			'orderAddress' : orderAddress,
			'orderEmail' : orderEmail,
			'orderUser' : orderUser,
			'orderSum' : orderSum,
		};
		$.ajax({
			url : url,
			data : postData,
			type : 'POST',
			success : function(result) {
				if (result) {
					$info('保存成功');
					doSearch();
				}
			}
		});
	}
	//删除
	function toDelete() {
		var row = $("#list").datagrid("getSelected");//获取选中行的值
		var data = {
			'orderId' : row.orderId
		}
		$.ajax({
			type : "post",
			url : "${ctx}/order/del",
			data : data,
			success : function(msg) {
				if (msg) {
					$info("删除成功!");
					doSearch();
				}
			}
		})
	}
</script>
<div id="tb"
	style="padding: 5px; height: auto; background-color: #daeef5; text-align: right;">
	<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
		onclick="toAdd(1)">添加</a>
</div>

<div class="easyui-layout" fit="true">
	<div region="east" style="width: 100%; height: 100%" id="eastTable">
		<table class="easyui-datagrid" style="width: 100%; height: 100%;"
			data-options="rownumbers:true,singleSelect:true,autoRowHeight:false,pagination:true,
				pageSize:10,toolbar:'#tb',onRowContextMenu:function(e, rowIndex, rowData){
					e.preventDefault();
					$(this).datagrid('selectRow',rowIndex);
					$('#menu-northTable').menu('show',{
						left: e.pageX,
						top: e.pageY
					});
				}"
			id="list">
			<input type="hidden"
				data-options="field:'orderId',width:'10%',halign:'center'" />
			<input type="hidden" id="adminMethod" name="adminMethod" />
			<thead>
				<tr>
					<th data-options="field:'orderPayment',width:'10%',halign:'center'">支付方式</th>
					<th
						data-options="field:'orderAddress',width:'10%',halign:'center',align:'center'">地址</th>
					<th
						data-options="field:'orderEmail',width:'10%',halign:'center',align:'center'">Email</th>

					<th
						data-options="field:'orderUser',width:'10%',halign:'center',align:'center'">用户</th>
					<th
						data-options="field:'orderTime',width:'10%',halign:'center',align:'center'">时间</th>
					<th
						data-options="field:'orderSum',width:'10%',halign:'center',align:'center'">总价</th>
				</tr>
			</thead>
		</table>
	</div>
</div>
<!-- 商品管理	-->
<div id="AdminAdd" class="easyui-dialog" title="用户管理"
	collapsible="false"
	style="width: 550px; height: 250px; padding: 0 5px; background: #fafafa;"
	data-options="closed:true,modal:true,minimizable: false,maximizable: false,
				iconCls: 'icon-save',
				buttons: [{
					text:'保存',
					iconCls:'icon-ok',
					handler:function(){
						save();
						$('#AdminAdd').dialog('close');
					}
				},{
					text:'取消',
					iconCls:'icon-cancel',
					handler:function(){
					$('#AdminAdd').dialog('close');
					}
				}]
			">
	<table width="100%">
		<tr height="50px">
			<td width="20%" style="text-align: right">支付类型：</td>
			<td width="30%"><input id="orderPayment" class="easyui-textbox"
				required="true" style="width: 90%; height: 22px" /><font
				color="red">*</font></td>
			<td width="20%" style="text-align: right">地址：</td>
			<td width="30%"><input id="orderAddress" class="easyui-textbox"
				required="true" style="width: 90%; height: 22px" /><font
				color="red">*</font></td>
		</tr>
		<tr height="50px">
			<td width="20%" style="text-align: right">Email：</td>
			<td width="30%"><input id="orderEmail" class="easyui-numberbox"
				style="width: 90%; height: 22px" /></td>
			<td width="20%" style="text-align: right">用户：</td>
			<td width="30%"><input id="orderUser" class="easyui-textbox"
				style="width: 90%; height: 22px"></td>
		</tr>
		<tr height="50px">
			<td width="20%" style="text-align: right">总价：</td>
			<td width="30%"><input id="orderSum" class="easyui-numberbox"
				style="width: 90%; height: 22px" /></td>
			<td><input id="orderId" type="hidden" /></td>
			<td></td>
		</tr>
	</table>
</div>
</div>
<!-- 数据列表上下文 -->
<div id="menu-northTable" class="easyui-menu" style="width: 120px;">
	<div onclick="toAdd(2)" data-options="iconCls:'icon-edit'">修改商品信息</div>
	<div class="menu-sep"></div>
	<div onclick="toDelete()" data-options="iconCls:'icon-remove'">删除商品信息</div>
</div>
<!-- 数据列表上下文 end -->
</body>
</html>